<?php
$output_dir = $_SERVER["DOCUMENT_ROOT"]."resources/img/nhom_nhac/";

    //lấy phần mở rộng của tập tin vừa save
     function findexts ($filename) 
     { 
        $filename = strtolower($filename) ; 
        $exts = split("[/\\.]", $filename) ; 
        $n = count($exts)-1; 
        $exts = $exts[$n]; 
        return $exts; 
     }

    if(isset($_FILES["anhnhomnhac"]))
    {
        if ($_FILES["anhnhomnhac"]["error"] > 0)
        {
          echo "Error: " . $_FILES["file"]["error"] . "<br>";
        }
        else
        {
            //$newName=$output_dir."conkhi.png";
            $newName=$output_dir.$_POST['nhomnhac_id'].".png";
            //$png;
            $ext = findexts ($_FILES['anhnhomnhac']['name']);
            
            switch($ext) {
                case 'jpg':
                case 'jpeg':
                    $png = imagecreatefromjpeg($_FILES['anhnhomnhac']['tmp_name']);
                    break;
                case 'gif':
                    $png = imagecreatefromgif($_FILES['anhnhomnhac']['tmp_name']);
                   break;
                case 'png':
                   $png = imagecreatefrompng($_FILES['anhnhomnhac']['tmp_name']);
                    break;
            }
            imagepng($png, $newName);
            //echo $ext;
            echo "Uploaded File :".$_FILES["anhnhomnhac"]["name"];
        }
    }
?>